package traceMyItems.business;

import java.util.*;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;


@PersistenceCapable
public class Item {
	private static final Logger log = Logger.getLogger(Item.class.getName());
	
	
	@Persistent
	private int priority;
	@Persistent
	private int id;
	@Persistent
	private String description;
	@Persistent
	private StatusType currentStatus;
	@Persistent
	private List<ItemStatus> traceability;
	@Persistent
	private User responsible;
	@Persistent
	private Team team;
	@Persistent
	private ItemType type;
	
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key=null;
	
	
	public void createKey() {
        //this.key = KeyFactory.createKey(User.class.getSimpleName(), strUsername+":"+strEmail);
		///TODO: Aun queda crear criterio de creacion de clave para esta clase
		this.key = null;
    }
	
	public Key getKey()
	{
		return key;
	}
	
	/**
	 * @return the priority
	 */
	public int getPriority() {
		return priority;
	}
	/**
	 * @param priority the priority to set
	 */
	public void setPriority(int priority) {
		this.priority = priority;
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the currentStatus
	 */
	public StatusType getCurrentStatus() {
		return currentStatus;
	}
	/**
	 * @param currentStatus the currentStatus to set
	 */
	public void setCurrentStatus(StatusType currentStatus) {
		this.currentStatus = currentStatus;
	}
	/**
	 * @return the traceability
	 */
	public List<ItemStatus> getTraceability() {
		return traceability;
	}
	/**
	 * @return the responsible
	 */
	public User getResponsible() {
		return responsible;
	}
	/**
	 * @param responsible the responsible to set
	 */
	public void setResponsible(User responsible) {
		this.responsible = responsible;
	}
	/**
	 * @return the team
	 */
	public Team getTeam() {
		return team;
	}
	/**
	 * @param team the team to set
	 */
	public void setTeam(Team team) {
		this.team = team;
	}
	/**
	 * @return the type
	 */
	public ItemType getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(ItemType type) {
		this.type = type;
	}
	
	public Item(){
		this.traceability = new ArrayList<ItemStatus>();
		 PersistenceManager pm = PMF.get().getPersistenceManager();
	        try {
	            pm.makePersistent(this);
	        } finally {
	            pm.close();
	        }
	}
}
